package com.ltz.service.login;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import util.DateUtil;

import com.ltz.dao.login.LoginDao;
import com.ltz.model.User;
import com.ltz.model.UserLog;

@Service
public class LoginService {
	
	@Resource
	private LoginDao loginDao;
	
	public User doLogin(HttpServletRequest request,String userName,String password){
		User user=loginDao.getUser(userName, password);
		//添加登录日志
		if(null!=user){
			String description="用户 \""+user.getUsername()+"\" 在 " +DateUtil.formatDate(new Date()) +" 登陆系统";
			UserLog userLog=new UserLog();
			userLog.setUserip(request.getRemoteAddr());
			userLog.setTitle(user.getUsername());
			userLog.setUserid(user.getUserid());
			userLog.setDescription(description);
			loginDao.add(userLog);
		}
		return user;
	}
}
